import { loginApi } from "@/api/login"
import { getToken, setToken, remvoeToken } from "@/request/token"
export default {
    namespaced: true,
    state: {
        token: getToken()
    },
    mutations: {
        setToken(state, token) {
            state.token = token
            setToken(token)
        },
        remvoeToken(state) {
            state.token = null
            remvoeToken()
        },
    },
    actions: {
        async loginActions({ commit }, userInfo) {
            let res = await loginApi(userInfo)
            commit('setToken', res.token)
        },
        logOutActions({ commit }) {
            commit('remvoeToken')
        }
    }
}